//
//  OtherView.m
//  BeautifulLockerRoom
//
//  Created by mac on 16/7/29.
//  Copyright © 2016年 Winny. All rights reserved.
//

#import "OtherView.h"
#import "DataModel.h"

@implementation OtherView

-(instancetype)initWithDataArray:(NSArray *)dataArray
{
    self = [super init];
    if (self)
    {
        self = [[OtherView alloc]init];
        [self createButtonWithDataArray:dataArray];
        NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
        
        [center addObserver:self selector:@selector(reciveNotice:) name:@"notice1" object:nil];
    }

    return self;
}
-(void)reciveNotice:(NSNotification *)notification
{
    NSInteger offset = [[notification.userInfo objectForKey:@"tag"]integerValue];
}

-(void)createButtonWithDataArray:(NSArray *)array
{
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    for (int i = 0; i < array.count; i ++)
    {
        DataModel * model = array[i];
        UIView * view= [[UIView alloc]initWithFrame:CGRectMake(i % 5 * WINDOWWIDTH / 5 , i / 5 * (WINDOWWIDTH/5+20), WINDOWWIDTH / 5, WINDOWWIDTH / 5 +20)];
        [bgView addSubview:view];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, WINDOWWIDTH /5, WINDOWWIDTH /5);
        
        [button setBackgroundImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.pic_url]]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, WINDOWWIDTH /5,WINDOWWIDTH /5, 20)];
        label.font = [UIFont systemFontOfSize:15];
        label.text = model.title;
        label.backgroundColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        [view addSubview:label];
        _viewHeight =  CGRectGetMaxY(view.frame) + 50;
        bgView.frame = CGRectMake(0, 0, WINDOWWIDTH, _viewHeight - 50);
    }
    
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, _viewHeight - 40, WINDOWWIDTH, 30)];
    label.text = @"————— 精品推荐 —————";
    label.textAlignment = 1;
    label.textColor = [UIColor grayColor];
    [self addSubview:label];
    [self addSubview:bgView];
    
}



-(void)buttonClick:(id)sender
{
    
}

@end
